﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;

namespace IssueVision.Data.Web
{
    /// <summary>
    /// LoginUser class client-side extensions
    /// </summary>
    public partial class LoginUser
    {
        /// <summary>
        /// Store the the value of "Keep Me Signed in"
        /// </summary>
        public bool IsPersistent { get; set; }

        /// <summary>
        /// Try validate the specified property for LoginUser class
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public bool TryValidateProperty(string propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            if (propertyName == "Name" || propertyName == "Password"
                || propertyName == "IsPersistent" || propertyName == "Roles")
            {
                var context = new ValidationContext(this, null, null)
                    { MemberName = propertyName };

                var validationResults = new Collection<ValidationResult>();

                if (propertyName == "Name")
                    return Validator.TryValidateProperty(Name, context, validationResults);
                if (propertyName == "Password")
                    return Validator.TryValidateProperty(Password, context, validationResults);
                if (propertyName == "IsPersistent")
                    return Validator.TryValidateProperty(IsPersistent, context, validationResults);
                if (propertyName == "Password")
                    return Validator.TryValidateProperty(Roles, context, validationResults);
            }
            return false;
        }
    }
}
